package com.guet.controller.teacher;

import com.guet.DTO.CoursewareDTO;
import com.guet.DTO.CoursewarePageDTO;
import com.guet.DTO.VideoPageDTO;
import com.guet.Entity.Courseware;
import com.guet.VO.CoursewareVO;
import com.guet.VO.VideoVO;
import com.guet.result.PageResult;
import com.guet.result.Result;
import com.guet.service.CoursewareService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("teacher/courseware")
@Slf4j
@CrossOrigin
public class CoursewareController {
    @Autowired
    private CoursewareService coursewareService;

    /**
     * 添加课件
     *
     * @param coursewareDTO
     * @return
     */
    @PostMapping("add")
    public Result<Object> addCourseware(@RequestBody CoursewareDTO coursewareDTO) {
        log.info("coursewareDTO: {}", coursewareDTO);
        coursewareService.addCourseware(coursewareDTO);
        return Result.success();
    }

    /**
     * 分页查询视频列表
     *
     * @param coursewarePageDTO
     * @return
     */
    @PostMapping
    public Result<PageResult> getPageList(@RequestBody CoursewarePageDTO coursewarePageDTO) {
        log.info("VideoPageDTO:{}", coursewarePageDTO);
        PageResult result = coursewareService.list(coursewarePageDTO);
        return Result.success(result);
    }

    /**
     * 根据id查询课件信息
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result<CoursewareVO> getVideoById(@PathVariable Integer id) {
        CoursewareVO coursewareVO = coursewareService.queryById(id);
        return Result.success(coursewareVO);
    }

    /**
     * 根据id删除课件资源
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result<Object> deleteCourseware(@PathVariable Integer id) {
        coursewareService.deleteById(id);
        return Result.success();
    }
}
